#!/usr/bin/env node

//const http = require('http')

//const addr = 'http://www.baidu.com'

//http.get(addr, (res) => {
  //console.log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`)
  //console.log(res.headers)
  //console.log()
  //res.pipe(process.stdout)
//})


const http = require('http'),
      log = console.log,
      url = require('url');

let addr = process.argv[2] || 'http://www.baidu.com',
    options = url.parse(global.encodeURI(addr));

    options.headers = {
        'User-Agent': '01-my-curl.js'
    };

http.get(options, (res) => {
    log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
    log(res.headers);
    log('');

    res.pipe(process.stdout);
});
